package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.jingjiu.homeservicesapi.domain.DiseaseCategory;
import com.jingjiu.homeservicesapi.util.R;


import com.jingjiu.homeservicesbiz.service.DiseaseCategoryServiceImpl;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 疾病分类：用于管理疾病的分类信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/system/category")
public class DiseaseCategoryController
{

    @Autowired
    private DiseaseCategoryServiceImpl diseaseCategoryService;


    /**
     * 查询疾病分类：用于管理疾病的分类信息列表
     */
    @GetMapping("/page")
    public R<Page<DiseaseCategory>> getPage(@ParameterObject Page<DiseaseCategory> page,
                                            @ParameterObject  DiseaseCategory diseaseCategory){
        // 调用 Service 层进行分页查询
        Page<DiseaseCategory> diseaseCategoryPage = diseaseCategoryService.selectPage(page, diseaseCategory);
        if(diseaseCategoryPage==null)
            return R.failed();
        return R.ok(diseaseCategoryPage);
    }





    /**
     * 新增保存疾病分类：用于管理疾病的分类信息
     */

    @PostMapping("/add")
    @ResponseBody
    public R addSave(@RequestBody DiseaseCategory diseaseCategory)
    {
        int row = diseaseCategoryService.insertDiseaseCategory(diseaseCategory);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }

    /**
     * 按id获取
     *
     * @param id   本我

     * @return {@link DiseaseCategory }
     */
    @GetMapping("/get/{id}")
    public R<DiseaseCategory> getById(@PathVariable("id") Long id)
    {
        DiseaseCategory diseaseCategory = diseaseCategoryService.selectDiseaseCategoryById(id);
        if(diseaseCategory==null)
            return R.failed();
        return  R.ok(diseaseCategory) ;

    }

    /**
     * 修改保存疾病分类：用于管理疾病的分类信息
     *
     * @param diseaseCategory 疾病类别
     */

    @PostMapping("/edit")
    @ResponseBody
    public R editSave(@RequestBody DiseaseCategory diseaseCategory)
    {   int row = diseaseCategoryService.updateDiseaseCategory(diseaseCategory);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }



    @PostMapping( "/remove")
    @ResponseBody
    public R remove(Long id)
    {   int row = diseaseCategoryService.deleteDiseaseCategoryById(id);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }
}
